import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;


public class FirstJunitcode {
	//Declare the objects and variable to use in @before, @test and @ after
	private WebDriver IEdriver;
	private String baseUrl="";
	
	@Before
	public void setUp() throws Exception {
		//Main @before code
		System.out.println("Heloo @Before");
		IEdriver = new InternetExplorerDriver(); // creating an object
		baseUrl = "http://www.youtube.com/";
		
		String s1; //Declaring variables
		String s2;
		s1 = "hello";
		s2 = " team";
		
		System.out.println(s1);
		System.out.println(s2);
		System.out.println(s1 + s2); // joining the strings
	
	}
	
	@Test
	public void testYtube1() throws Exception {
		System.out.println("Heloo @Test2");
		// All YT related test steps will be performed within this function or method
		String iSearchTerm= "";
		String oSearchRestults;
		int  iWait=2000,i;
		String a1="Testing"; String a2="Automation"; String a3="Training";
		String eSearchResults = "About 13,000 results";
		for (i=1; i<4; i++)
		{
			if (i==1)
			{
				iSearchTerm = "Selenium" + " " + a1;
			}
			
			if (i==2){
				iSearchTerm = "Selenium" + " " + a2;
			}
			if (i==3){
				iSearchTerm = "Selenium" + " " + a3;
			}
				
        IEdriver.get(baseUrl); // sel WD method that navigates to the browser to the url
		// where part: xpath is "//input[@id='masthead-search-term']"
        // What Part: Enter text into the search - QTP
        
       IEdriver.findElement(By.xpath("//input[@id='masthead-search-term']")).sendKeys(iSearchTerm);
      // "//*[@id="masthead-search-term"] xpatch copy from firebug
       Thread.sleep(iWait); // iWait is milliseconds, in this case 2000 = 2 seconds
       
       IEdriver.findElement(By.xpath("//button[@id='search-btn']")).click();
       // xpath = //*[@id="search-btn"]
       
       Thread.sleep(iWait);
       
       oSearchRestults = IEdriver.findElement(By.xpath("//p[@class='num-results']")).getText();
       // xpath = /html/body/div/div[2]/div/div/div/p
       Thread.sleep(iWait);
       System.out.println("The # of rearches: "+ oSearchRestults);
       if (eSearchResults.equals(oSearchRestults))
       {
    	   System.out.println("pass");
       }
       else {
    	   System.out.println("Fail");
       }
          }
	}
	@After
	public void tearDown() throws Exception {
		System.out.println("Heloo @After");
		IEdriver.quit();
	}
}